package daily;

import java.util.Optional;

public class Person {

    /**
     * 人可能有汽车 也可能没有汽车
     */
    private Optional<Car> car;

    public Optional<Car> getCar() {
        return car;
    }


    public String getCarInsuranceName(Optional<Person> person) {
        // todo flatMap
        return person.flatMap(Person::getCar).flatMap(Car::getInsurance)
                .map(Insurance::getName).orElse("Unknown");
    }
}




